import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:xingsu/page/user/forget_page.dart';
import 'package:xingsu/page/user/register_page.dart';
import 'package:xingsu/util/use_preferences.dart';
import '../../mine/viewModel/mine_viewmodel.dart';

class LoginViewModel extends GetxController {
  final TextEditingController phoneController = TextEditingController();
  final TextEditingController pwdController = TextEditingController();

  void loginClick() {
    String phone = phoneController.text;
    String pwd = pwdController.text;
    if (phone.isEmpty) {
      Fluttertoast.showToast(msg: "手机号不能为空");
      return;
    }

    if (!phone.isPhoneNumber) {
      Fluttertoast.showToast(msg: "手机号格式不准确");
      return;
    }

    if (pwd.isEmpty) {
      Fluttertoast.showToast(msg: "密码不能为空");
      return;
    }

    Get.back();
    UserPreferences.setIsLogin(true);
    MineViewModel _viewModel = Get.find();
    _viewModel.changeLogin();
  }

  void registerClick() {
    Get.to(() => RegisterPage());
  }

  void forgetClick() {
    Get.to(() => ForgetPage());
  }
}
